import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDGem {
	/**ID*/
	id,
	/**显示等级*/
	level,
	/**下级宝石id*/
	nextLeveId,
	/**1级宝石id*/
	initialGem,
	/**装备宝石类型*/
	group,
	/**宝石经验*/
	exp,
	/**升级需求经验值*/
	upgradeExp,

	/**枚举数量*/
	EnumCount
}



export class CDGem{
	/**ID*/
	public id: number;
	/**显示等级*/
	public level: number;
	/**下级宝石id*/
	public nextLeveId: number;
	/**1级宝石id*/
	public initialGem: number;
	/**装备宝石类型*/
	public group: number;
	/**宝石经验*/
	public exp: number;
	/**升级需求经验值*/
	public upgradeExp: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDGem.id: return this.id;
			case E_CDGem.level: return this.level;
			case E_CDGem.nextLeveId: return this.nextLeveId;
			case E_CDGem.initialGem: return this.initialGem;
			case E_CDGem.group: return this.group;
			case E_CDGem.exp: return this.exp;
			case E_CDGem.upgradeExp: return this.upgradeExp;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDGem.id: this.id = v; break;
			case E_CDGem.level: this.level = v; break;
			case E_CDGem.nextLeveId: this.nextLeveId = v; break;
			case E_CDGem.initialGem: this.initialGem = v; break;
			case E_CDGem.group: this.group = v; break;
			case E_CDGem.exp: this.exp = v; break;
			case E_CDGem.upgradeExp: this.upgradeExp = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDGem> = new HashMap<number, CDGem>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDGem[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDGem();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].level = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].nextLeveId = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].initialGem = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].group = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].exp = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].upgradeExp = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDGem{
		return this.datas ? this.datas.get(id) : null;
	}
}
